//
//  FWHomeViewController.swift
//  DBS
//
//  Created by 王方伟 on 2017/4/7.
//  Copyright © 2017年 wfw. All rights reserved.
//

import UIKit

class FWHomeViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupNavigation()
        setupContentView()
        
    }

}

extension FWHomeViewController {
    fileprivate func setupNavigation() {
        // 1.设置左侧的Item
        navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "logo")
        
        // 2.设置右侧的Item
        let size = CGSize(width: 40, height: 40)
        let historyItem = UIBarButtonItem(imageName: "image_my_history", highImageName: "Image_my_history_click", size: size)
        let searchItem = UIBarButtonItem(imageName: "btn_search", highImageName: "btn_search_clicked", size: size)
        let qrcodeItem = UIBarButtonItem(imageName: "Image_scan", highImageName: "Image_scan_click", size: size)
        navigationItem.rightBarButtonItems = [historyItem, searchItem, qrcodeItem]
        
        view.backgroundColor = UIColor.white
        automaticallyAdjustsScrollViewInsets = false
    }
    
    fileprivate func setupContentView(){
        let titleArray = FWHomeService.loadTitleData()
        
        let titles = titleArray.map({$0.title})
        let style = FWTitleStyle()
        style.isScrollEnable = true
        style.isShowBottomLine = true
        var childVCs = [UIViewController]()
        
        for type in titleArray {
            let childVC = FWAnchorViewController()
            childVC.homeType = type
            childVCs.append(childVC)
        }
        
        let frame = CGRect(x: 0, y: 64, width: view.bounds.width, height: view.bounds.height - 64)
        let pageView = FWPageView(frame:frame, titles: titles, childVCs: childVCs, parentVC: self, style: style)
        view.addSubview(pageView);
    }
    
    @objc func onClickRightItem(){
        print("onClickRightItem")
    }
}
